//
//  ViewController.swift
//  ThreadSwiftDemo
//
//  Created by 李煜 on 2024/6/19.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        m1()
        m2()
        m3()
        
        
        //以下 是发现button addtarget方法selector的带参数的不同
        let b = UIButton(type: .custom)
        b.addTarget(self, action: #selector(click(btn:)), for: .touchUpInside)
        b.setTitle("click me ", for: .normal)
        b.center = view.center
        b.backgroundColor = .orange
        b.sizeToFit()
        view.addSubview(b)
    }
    
    func m1() {
        let thread = Thread(target: self, selector: #selector(param), object: "111")
        thread.name = "target thread"
        thread.threadPriority = 0.8
        thread.start()
    }
    func m2() {
        Thread.detachNewThreadSelector(#selector(param), toTarget : self, with : "detachNewThread")
    }
    func m3() {
        performSelector(inBackground: #selector(param), with: "performSelector")
    }
    @objc func  param(_ obj: Any) {
        print(Thread.current,obj)
    }
    
    @objc func click(btn: Any) {
        print("btn:\(btn)")
        
    }
}

